package com.ww.springboot.mybatis.config;


import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;


/**
 * 描述：workId 设置雪花算法的workId dataCenterId
 *
 * @author wanwei
 * @since 2021-10-29 11:20
 */

//@Configuration
public class MybaitsConfiguration {

	@Autowired
	private SqlSessionFactory sqlSessionFactory;

	@PostConstruct
	public void init() {
		MybatisConfiguration configuration = (MybatisConfiguration) sqlSessionFactory.getConfiguration();
		GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration);
		IdentifierGenerator identifierGenerator = new DefaultIdentifierGenerator(1,2);
		globalConfig.setIdentifierGenerator(identifierGenerator);
	}
}

